package com.four.user.service.impl;

import com.four.user.entity.City;
import com.four.user.dao.CityMapper;
import com.four.user.service.ICityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.vo.CityVo;
import org.elasticsearch.common.recycler.Recycler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-12-22
 */
@Service
public class CityServiceImpl extends ServiceImpl<CityMapper, City> implements ICityService {

    @Autowired
    private CityMapper cityMapper;

    /**
     * 查询地址
     * 三级树
     * @return
     */
    @Override
    public List<CityVo> threeCity() {
        //查询第一级省
        List<CityVo> cityList1=cityMapper.getTreeOne(0);
        //遍历所有第一级地址，得到编号，就有了第二级的父级id
        for (CityVo city : cityList1) {
            Integer id = city.getId();
            List<CityVo> cityList2=cityMapper.getTreeOne(id);
            city.setChildren(cityList2);
            for (CityVo city1 : cityList2) {
                Integer id1 = city1.getId();
                List<CityVo> cityList03=cityMapper.getTreeOne(id1);
                city1.setChildren(cityList03);
            }
        }
        return cityList1;
    }
}
